package com.ruoyi.project.alipay;

import com.google.common.collect.Maps;
import com.ruoyi.project.WxMoudle.Bases.WeixinConfig;
import com.ruoyi.project.pickToBC.SendWeChat;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Map;

public class Test {
    public static void main(String[] args) throws Exception {

        toPickMoney("1","o3KmFt-Pg-a2pj_HI02oJY0yx3rc");

    }


    public static void toPickMoney(String money ,String openId) throws Exception {
        //提现金额(单位:元)
        //元转换为分,微信支付已分为单位
        BigDecimal sumAmount = new BigDecimal(money);
        Map<String, String> map = Maps.newHashMap();
        //乘以100，转换为分
        BigDecimal transAmt = sumAmount.multiply(new BigDecimal(100));


        //订单号
        String OrderNum = LocalDate.now().toString().replace("-", "") + LocalTime.now().toString().replace("-", "").replace(":", "").replace(".", "");
        //订单号
        map.put("partner_trade_no", OrderNum);
        map.put("mch_appid", WeixinConfig.APPID);
        map.put("mchid", WeixinConfig.MACHINEDID);
        map.put("check_name","NO_CHECK");
        //随机字符串
        map.put("nonce_str", OtherUtils.getNonceStr().toString());
        map.put("spbill_create_ip",WeixinConfig.SPBILL_CREATE_IP);
        //openid("c从数据库中查询")
        map.put("openid", openId);
        //金额
        map.put("amount", transAmt.toString());
        ////企业付款操作说明信息
        map.put("desc", "提现测试,钱就不返还了");

        //调用支付
        String returnInfo =  SendWeChat.toWeChat(map, WeixinConfig.PAY_TO_PERON);
        Map<String,String> resultMap = OtherUtils.readStringXmlOut(returnInfo);

        if(resultMap.containsKey("result_code") && "SUCCESS".equals(resultMap.getOrDefault("result_code",""))){
            System.out.println("提现成功");
            System.out.println("返回结果："+returnInfo);
        }else{
            System.out.println("提现失败");
            System.out.println("返回结果："+returnInfo);
        }
    }

}
